package sebastiankerckhof.scene.texture;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import sebastiankerckhof.math.Color3f;

public class BasicTexture implements Texture{

	public BufferedImage image;
	
	public BasicTexture(String path) throws IOException {
		//System.out.println(path);
    	this(ImageIO.read(new File(path)));
	}
	
	public BasicTexture(BufferedImage image){
		this.image = image;
	}
	
	public Color3f getColor(TexCoord2f tc) {
		int x = (int) (tc.x * this.image.getWidth() - 1);
		int y = (int) (tc.y * this.image.getHeight() - 1);
		System.out.println(x+" "+y);
		Color color = new Color(this.image.getRGB(x % image.getWidth()+1, y % image.getHeight()+1));
		Color3f result = new Color3f();
		result.set(color);
		return result;
	}
}
